//package com.icangya.admin;
//
//import com.alibaba.fastjson.JSONObject;
//import com.icangya.Utils.*;
//import com.icangya.Value.StaticValue;
//import com.icangya.domain.FbPayInfo;
//import com.icangya.domain.RwGoodOrder;
//import com.icangya.domain.User;
//import com.icangya.service.IDomainService;
//import com.icangya.service.IFbWxSuitcaseService;
//import com.icangya.service.IFootUserService;
//import com.icangya.weixin.sdk.WXPayUtil;
//import org.slf4j.LoggerFactory;
//import org.springframework.beans.factory.annotation.Autowired;
//import org.springframework.web.bind.annotation.*;
//
//import javax.annotation.Resource;
//import javax.servlet.http.HttpServletRequest;
//import javax.servlet.http.HttpServletResponse;
//import java.net.URLEncoder;
//import java.util.*;
//
//import static com.icangya.Value.FootBall.FOOT_USER_SESSION;
//import static com.icangya.Value.StaticValue.WX.PANDE_PAY_URL;
//
//
//@CrossOrigin
//@RestController
//@RequestMapping(value = "/pay/")
//public class PayDemoControlller {
//
//    private org.slf4j.Logger logger = LoggerFactory.getLogger(this.getClass());
//
//    @Autowired
//    private IFootUserService iFootUserService;
//
//    @Autowired
//    private IFbWxSuitcaseService iFbWxSuitcaseService;
//
//    @Autowired
//    private IDomainService iDomainService;
//
//    @Autowired
//    private IRedWineGameService iRedWineGameService;
//
//    @Resource
//    com.icangya.lifePay.http.HttpClientUtil httpClientUtil;
//
//
//    //熊猫商城支付接口
//    @RequestMapping(value = "pandePay1",method = RequestMethod.POST)
//    public JSONObject pandePay(long id, HttpServletRequest request, HttpServletResponse response) throws Exception {
//
//
////        请求数据示例：http://api.baifupass.com/topay/bftpay/getcode
//
////        加密实例：#0.02#d650580b#http://18*****8/test.php#1498734573#无#WX_SCANCODE_JSAPI  ( Key 值用#拼接 注意key值需要ascii 排序 )
//
////        body: appid=d650580b&trxType=WX_SCANCODE_JSAPI&amount=0.02&down_trade_no=1498734699&goodsname=%E6%97%A0&backurl=http%3A%2F%2F18%2A%2A%2A%2A%2A8%2Ftest.php&sign=308FF974F18EDA71826A732092D4D219
//
//        RwGoodOrder rwGoodOrder = iRedWineGameService.getRwGoodOrderById(id);
//
//        int money = rwGoodOrder.getSumPices();
//        String appid = "4a103b9d";
//        String backurl = URLEncoder.encode(StaticValue.WX.BASE_URL + "/pay/pandePayCallback");
////        String down_trade_no = WXPayUtil.generateUUID();
////        String down_trade_no = FormatUtil.getStringDate();
//        String down_trade_no = String.valueOf(new Date().getTime());
//        String goodsName = URLEncoder.encode("充值");
//        String signkey="9391e150203047c2431b2aeaaa36ed4a";
////        signkey:9391e150203047c2431b2aeaaa36ed4a
//
////        String needToMd5 = "appid="+appid+"&trxType=WX_SCANCODE_JSAPI&amount="+amount+"&down_trade_no="+down_trade_no+"&goodsname="+goodsName+"&backurl="+backurl+"#"+ signkey;
//        String needToMd5 = "#"+money+"#"+appid+"#"+backurl+"#"+down_trade_no+"#"+goodsName+"#WX_SCANCODE_JSAPI"+"#"+ signkey;
////        logger.info("==============================");
////        logger.info(needToMd5);
//        String MD5STR = WXPayUtil.MD5(needToMd5);
//        String sign = MD5STR;
//
//        Map<String, String> params = new HashMap<String,String>();
//        params.put("appid",appid);
//        params.put("trxType","WX_SCANCODE_JSAPI");
//        params.put("amount", String.valueOf(money));
//        params.put("down_trade_no",down_trade_no);
//        params.put("goodsname",goodsName);
//        params.put("backurl",backurl);
//        params.put("sign",sign);
////        String str = "appid="+appid+"&trxType=WX_SCANCODE_JSAPI&amount="+amount+"&down_trade_no="+down_trade_no+"&goodsname="+goodsName+"&backurl="+backurl+"&sign="+sign;
////        logger.info("==============================");
////        logger.info(params.toString());
//
//        String returnStr = httpClientUtil.post(PANDE_PAY_URL,null,params);
//
////        logger.info("==============================");
////        logger.info("======熊猫支付后，response返回结果======");
////        logger.info(returnStr);
//
//        JSONObject jsonObject = (JSONObject) JSONObject.parse(returnStr);
//        String bftcode = jsonObject.getString("bftcode");
//        String msg = jsonObject.getString("msg");
//        JSONObject jsonResult = jsonObject.getJSONObject("result");
//        String orderNumber = jsonObject.getString("orderNumber");
//        String amount = jsonObject.getString("amount");
//        String qrCode = jsonObject.getString("qrCode");
//
//        logger.info("===========================================");
//        logger.info(jsonResult.toString());
//        logger.info("===========================================");
//        if ("1000".equals(bftcode)){
////            return "success";
//            return JSONUtils.getRoot(0,"success",jsonResult);
//        }
//
////        return "faild";
//        return JSONUtils.getRoot(-1,"faild",jsonResult);
//
////        {"bftcode":"1000","msg":"订单处理成功",
////                "result":{
////                    "orderNumber":"bft_d650580b_3_170629071403065",
////                    "amount":"10.02",
////                    "qrCode":"https://ybccb.izhongyin.net/middlepaytrx/wx/authRedirect/YBCCB/WX20170629191403MS55e47"
////                }
////        }
//    }
//
//
//    //熊猫商城支付接口
//    @RequestMapping(value = "pandePayCallback")
//    @PostMapping
//    @ResponseBody
//    public String pandePayCallback(HttpServletRequest request, HttpServletResponse response) throws Exception {
//
//        String bftcode = String.valueOf(request.getAttribute("bftcode"));
//        String orderNumber = String.valueOf(request.getAttribute("orderNumber"));
//        String amount = String.valueOf(request.getAttribute("amount"));
//        String real_total_fee = String.valueOf(request.getAttribute("real_total_fee"));
//        String sign = String.valueOf(request.getAttribute("sign"));
//
//        logger.info("========回调成功了吗？=========");
//        logger.info("==bftcode:"+bftcode+"==orderNumber:"+orderNumber+"==amount:"+amount+"==real_total_fee:"+real_total_fee+"==sign:"+sign);
//
//        if ("1000".equals(bftcode)){
//            logger.info("========回调成功了，并且通知支付商了=========");
//            return "SUCCESS";
//        }

//    }

//
//    //熊猫商城支付接口
//    @RequestMapping(value = "pandePayCallback")
//    @ResponseBody
//    public String pandePayCallback(HttpServletRequest request, HttpServletResponse response) throws Exception {
//
//        String bftcode = String.valueOf(request.getAttribute("bftcode"));
//        String orderNumber = String.valueOf(request.getAttribute("orderNumber"));
//        String amount = String.valueOf(request.getAttribute("amount"));
//        String real_total_fee = String.valueOf(request.getAttribute("real_total_fee"));
//        String sign = String.valueOf(request.getAttribute("sign"));
//
//        logger.info("========回调成功了吗？=========");
//        logger.info("==bftcode:"+bftcode+"==orderNumber:"+orderNumber+"==amount:"+amount+"==real_total_fee:"+real_total_fee+"==sign:"+sign);
//
//        if ("1000".equals(bftcode)){
//            logger.info("========回调成功了，并且通知支付商了=========");
//            return "SUCCESS";
//        }
//
//        return "faild";
//
//    }

//    //第三方支付（啊哲）
////    @RequestMapping(value = "mypay")
//    public JSONObject mypay(@RequestParam int money, HttpServletRequest request, HttpServletResponse response) throws Exception {
//
//        //此处应该处理一下金额
//        int realmoney = 200000;
//
//        switch (money){
////            case 2 :
////                realmoney = 200;
////                break;
//            case 5 :
//                realmoney = 500;
//                break;
//            case 10 :
//                realmoney = 1000;
//                break;
//            case 20 :
//                realmoney = 2000;
//                break;
//            default:
//                realmoney = 200000;
//                return JSONUtils.getRoot(-1,"faild","bug");
////                break;
//        }
//
//        System.out.println(money+"充值金额！");
//        int c = CountUtils.getCountInMinToMax(1,8);
//        realmoney  = realmoney + c;
//
//        com.icangya.domain.PayBean payBean = iFootUserService.getPaybeanByStatus();
//
//        User user = (User) request.getSession().getAttribute(FOOT_USER_SESSION);
//        String merchant_id  = payBean.getMchId();//"3842928068623584";
//        String pay_type  = "wechat.jsurl";
//        String mch_trade_id  = WXPayUtil.generateUUID();//订单号
//        String time_start  = FormatUtil.getStringDate();
//        String body  = "充值";
//        String total_fee  = String.valueOf(realmoney);
//        String spbill_create_ip  = CusAccessObjectUtil.getIpAddress(request);
//        String sub_appid  = payBean.getWxAppid();
//        String sub_openid  = user.getOpenId();
//        String nonce_str = WXPayUtil.generateNonceStr();
//        String notify_url  = "http://"+iDomainService.getDoamin().get(0).getDomainUrl()+ "/foot/user/weixinpay/callback";
//        String callback_url  ="http://"+iDomainService.getDoamin().get(0).getDomainUrl()+ "/slyderAdventures/index.html";
//
//
//        Map<String ,String> data = new HashMap<String ,String>();
//        data.put("merchant_id",merchant_id);
//        data.put("pay_type",pay_type);
//        data.put("mch_trade_id",mch_trade_id);
//        data.put("time_start",time_start);
//        data.put("body",body);
//        data.put("total_fee",total_fee);
////        data.put("total_fee","1");
//        data.put("spbill_create_ip",spbill_create_ip);
////        data.put("sub_appid",sub_appid);
////        data.put("sub_openid",sub_openid);
//        data.put("nonce_str",nonce_str);
//        data.put("notify_url",notify_url);
//        data.put("callback_url",callback_url);
//        data.put("settle_type","0");
//
//        String sign = WXPayUtil.generateSignature(data,payBean.getMchKey());
//
//        data.put("sign",sign);
//
//        org.json.JSONObject jsonObject = new org.json.JSONObject(data);
//        Set<String> keySet = data.keySet();
//        String[] keyArray = keySet.toArray(new String[keySet.size()]);
//        Arrays.sort(keyArray);
//        for (String k : keyArray) {
//            if (data.get(k).trim().length() > 0) {// 参数值为空，则不参与签名
//                jsonObject.put(k,data.get(k).trim());
//            }
//        }
//        String queryStr = String.valueOf(jsonObject);
//        String result_str = httpClientUtil.post(payBean.getRequestUrl(),queryStr);
//
////        String result_str = PqTest.sendHtpps(data,payBean.getRequestUrl());
////        String result_str = HttpHelper.doMyPost(payBean.getRequestUrl(),data);
//        logger.info("==============测试请求返回值=============");
//        logger.info("result:"+result_str);
//        logger.info("=============测试请求返回值==============");
//
//
//        JSONObject myJsonObject = JSONObject.parseObject(result_str);
//        JSONObject datajson = myJsonObject.getJSONObject("data");
//
//        Integer code = myJsonObject.getInteger("code");
//        Integer result_code = datajson.getInteger("result_code");
//
//        String pay_url = datajson.getString("pay_url");
//
//        if (code==0&&result_code==0){
//
//
//            FbPayInfo fbPayInfo = new FbPayInfo();
//            fbPayInfo.setBank_type("--");
//            fbPayInfo.setCh_trade_id("--");
//            fbPayInfo.setCode("--");
//            fbPayInfo.setFee_type("--");
//            fbPayInfo.setIs_subscribe("--");
//            fbPayInfo.setMch_trade_id(mch_trade_id);
//            fbPayInfo.setMerchant_id(merchant_id);
//            fbPayInfo.setMsg("--");
//            fbPayInfo.setNonce_str(nonce_str);
//            fbPayInfo.setOpenid(sub_openid);
//            fbPayInfo.setOut_trade_id(mch_trade_id);
//            fbPayInfo.setPay_type(pay_type);
//            fbPayInfo.setResult_code("--");
//            fbPayInfo.setTotal_fee(total_fee);
//            fbPayInfo.setTrade_id("--");
//            fbPayInfo.setTrade_info("--");
//            fbPayInfo.setTrade_state("--");
//
//            long myid = iFbWxSuitcaseService.savePayInfo(fbPayInfo);
//            if (myid > 0){
//                return JSONUtils.getRoot(0,"success",pay_url);
//            }
//            return JSONUtils.getRoot(-1,"faild","myid <= 0");
//
//        }else{
//            String msg =  myJsonObject.getString("msg");
//            return JSONUtils.getRoot(1,"faild",msg);
//        }
//
//    }
//
//
////    @RequestMapping(value = "paymoney")
////    public void paymoney(@RequestParam String money,HttpServletRequest request,HttpServletResponse response) throws Exception {
////
////        User user = (User) request.getSession().getAttribute(FOOT_USER_SESSION);
////
////        //KEY 使用相应分配的商户key即可
////        PayBean trans = new PayBean();
////        trans.setAppId(StaticValue.DZ_APPID);
////        trans.setAmount(0.10);//支付 2 元
////        trans.setMerchantOrderNo(WXPayUtil.generateNonceStr());
////        trans.setPayChannel(1203);
////        trans.setProductDescription("充值");
////        trans.setProductName("充值");
////        trans.setReqDate(FormatUtil.getStringDate());
////        trans.setNotifyUrl("http://www.xiaoxiaokm.com/pay/callback");//用户支付完成通知地址
////        trans.setReturnUrl("http://www.xiaoxiaokm.com/slyderAdventures/index.html");//用户支付完成跳转地址
////        trans.setExtMsg("321");//扩展参数
////
////        Map<String ,String> mapdata = new HashMap<String,String>();
////
////        mapdata.put("Amount", String.valueOf(trans.getAmount()));
////        mapdata.put("AppId",trans.getAppId());
////        mapdata.put("BuyerId",user.getOpenId());
////        mapdata.put("ExtMsg",trans.getExtMsg());
////        mapdata.put("MerchantOrderNo",trans.getMerchantOrderNo());
////        mapdata.put("NotifyUrl",trans.getNotifyUrl());
////        mapdata.put("PayChannel", String.valueOf(trans.getPayChannel()));
////        mapdata.put("ProductDescription",trans.getProductDescription());
////        mapdata.put("ProductName",trans.getProductName());
////        mapdata.put("ReqDate",trans.getReqDate());
////        mapdata.put("ReturnUrl",trans.getReturnUrl());
////        mapdata.put("WechatAppId",StaticValue.WX.AppId);
////
////
////
////        mapdata.put("Sign",WXPayUtil.generateSignature(mapdata,StaticValue.DZ_KEY));
////        logger.info("================");
////        logger.info("======支付中...==========");
////        logger.info("================");
////
////        FormSubmitUtils.doPost(StaticValue.GETWAY_URL,mapdata);
//////        response.sendRedirect(HttpHelper.doPost(StaticValue.GETWAY_URL,mapdata));
////
//////        PrintWriter out = response.getWriter();
//////        out.println();
//////        out.flush();
//////        out.close();
////
//////        TransUtil tu = new TransUtil();
//////        byte[] reponse = tu.packet_payBean(trans, StaticValue.DZ_KEY);
//////
//////        //URL 使用相应地址即可
//////        String response = CommonUtil.post(StaticValue.GETWAY_URL, reponse);
//////
//////        logger.info(response);
////
//////        Map<String, String> resMap = mapper.readValue(response, Map.class);
//////        String sign = SignUtil.getSign(resMap, StaticValue.DZ_KEY);
//////
//////        if (!trans.getSign().equals(sign)) {
//////            System.out.println("签名正确");
//////            //判断返回码
//////        }else{
//////            System.out.println("签名失败");
//////        }
////    }
//
////    @RequestMapping(value = "callback")
////    public void callback(HttpServletRequest request , HttpServletResponse response) throws Exception {
////
////        logger.info("================");
////        logger.info("================");
////        logger.info("======支付成功，成功回调callback==========");
////        logger.info("================");
////    }
//}
